package com.example.hospital.api.service.impl;

import cn.hutool.core.lang.hash.Hash;
import cn.hutool.core.map.MapUtil;
import com.example.hospital.api.db.dao.MedicalDeptDao;
import com.example.hospital.api.service.MedicalDeptService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * @author Baiken
 * @version 1.0
 * @description: 科室service
 * @date 2024/9/4 下午4:26
 */

@Service
public class MedicalDeptServiceImpl implements MedicalDeptService {

    @Resource
    private MedicalDeptDao medicalDeptDao;

    @Override
    public ArrayList<HashMap> searchAll() {
        return medicalDeptDao.searchAll();
    }

    @Override
    public HashMap searchDeptAndSub() {
        ArrayList<HashMap> list = medicalDeptDao.searchDeptAndSub();
        LinkedHashMap map = new LinkedHashMap();
        for(HashMap one : list){
            Integer deptId = MapUtil.getInt(one,"deptId");
            Integer subId = MapUtil.getInt(one,"subId");
            String deptName = MapUtil.getStr(one,"deptName");
            String subName = MapUtil.getStr(one,"subName");
            if(map.containsKey(deptName)){
                ArrayList<HashMap> subList = (ArrayList<HashMap>) map.get(deptName);
                subList.add(new HashMap(){
                    {
                        put("subId",subId);
                        put("subName",subName);
                    }
                });
            }else {
                map.put(deptName,new ArrayList<>(){
                    {
                        add(new HashMap() {
                            {
                                put("subId",subId);
                                put("subName",subName);
                            }
                        });
                    }
                });
            }
        }
        return map;
    }
}
